﻿using System;
using System.IO;
using System.Windows;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Ribbon;
using UIT.ScrumTool.Client.Controller;
using UIT.ScrumTool.Client.View.Backlog;
using UIT.ScrumTool.Client.View.Project;

namespace UIT.ScrumTool.Client.View.Admin
{
    /// <summary>
    /// Interaction logic for frmAdminstrator.xaml
    /// </summary>
    public partial class wndAdminstrator : DXRibbonWindow
    {
        //Thuoc tinh 
        private readonly uctrlUsers _uctrkUsers = new uctrlUsers();
        private DataTemplate template;

        private uctrlProject _uctrlProject = new uctrlProject();
        public static object temp;
        

        public wndAdminstrator()
        {
            InitializeComponent();
            DeleteTempFile();
        }

        // Delete All File In temp Directory
        public static void DeleteTempFile()
        {
            string[] files = Directory.GetFiles(System.Windows.Forms.Application.StartupPath + "\\temp");
            foreach (var file in files)
            {
                try
                {
                    File.Delete(file);
                }
                catch (Exception)
                {
                    continue;
                }

            }
        }

        #region Thao Tac Admins

        private void glyThemes_ItemClick(object sender, GalleryItemEventArgs e)
        {
            var themeName = (string) e.Item.Caption;
            themeName = themeName.Replace(" ", string.Empty);
            ThemeManager.SetTheme(this, Theme.FindTheme(themeName));
        }

        private void gridMain_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                gridMain.Children.Add(_uctrkUsers);
            }
            catch
            {
            }
        }

        private void btnRefresh_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserCtrl.UserRefresh(uctrlUsers.userBindingListComplete);
        }

        private void btniAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            _uctrkUsers.grid.View.Headers.Clear();
            template = _uctrkUsers.FindResource("cardViewInsertionRow") as DataTemplate;
            _uctrkUsers.grid.View.Headers.Add(template);
        }

        #endregion

        private void btniDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserCtrl.UserDelete(uctrlUsers.userBindingListComplete, _uctrkUsers.grid);
        }

        private void drwAdminstrator_Loaded(object sender, RoutedEventArgs e)
        {
            //   UserCtrl.TableUser(uctrlUsers.userBindingListComplete);
        }
    }
}